# 推导式

'''
列表推导式 
[表达式 for item in 可迭代对象]
[表达式 for item in 可迭代对象 if 条件判断]
'''
y = [x for x in range(1, 5)]
print(y)

y = [x * 2 for x in range(1, 5)]
print(y)

y = [x for x in range(1, 50) if x % 5 == 0]
print(y)

y = [(row, col) for row in range(1, 5) for col in range(1, 5)]
print(y)

y = [(row, col) for row in range(1, 7) if row % 2 != 0 for col in range(1, 7) if col % 2 == 0]
print(y)


'''
字典推导式
{key表达式: value表达式 for item in 可迭代对象}
'''
text = 'you could not see my tears cause I am in the water'
char_count = {c: text.count(c) for c in text}
print(char_count)


'''
集合推导式
{表达式 for item in 可迭代对象}
{表达式 for item in 可迭代对象 if 条件判断}
'''
y = {x for x in range(1, 50) if x % 5 == 0}
print(y)

'''
生成器推导式（生成元组）
(表达式 for item in 可迭代对象)
(表达式 for item in 可迭代对象 if 条件判断)
'''
y = (x for x in range(1, 50) if x % 5 == 0)
print(y)
for i in y:
    print(i, end=' ')